-- postgresql fixed asets foreign keys

ALTER TABLE A_ASSET ADD CONSTRAINT AParentAsset_AAsset FOREIGN KEY (A_Parent_Asset_ID) REFERENCES A_ASSET;

ALTER TABLE A_ASSET_ACCT ADD CONSTRAINT AAssetSpread_AAssetAcct FOREIGN KEY (A_Asset_Spread_ID) REFERENCES A_ASSET_SPREAD;

ALTER TABLE A_ASSET_ACCT ADD CONSTRAINT ADepreciationConv_AAssetAcct FOREIGN KEY (A_Depreciation_Conv_ID) REFERENCES A_DEPRECIATION_CONVENTION;

ALTER TABLE A_ASSET_ACCT ADD CONSTRAINT ADepreciationMethod_AAssetAcct FOREIGN KEY (A_Depreciation_Method_ID) REFERENCES A_DEPRECIATION_METHOD;

ALTER TABLE A_ASSET_ACCT ADD CONSTRAINT ADepreciationTableHeader_AAsse FOREIGN KEY (A_Depreciation_Table_Header_ID) REFERENCES A_DEPRECIATION_TABLE_HEADER;

ALTER TABLE A_ASSET_ADDITION ADD CONSTRAINT CInvoice_AAssetAddition FOREIGN KEY (C_Invoice_ID) REFERENCES C_INVOICE;

ALTER TABLE A_ASSET_ADDITION ADD CONSTRAINT GLJournalBatch_AAssetAddition FOREIGN KEY (GL_JournalBatch_ID) REFERENCES GL_JOURNALBATCH;

ALTER TABLE A_ASSET_CHANGE ADD CONSTRAINT AParentAsset_AAssetChange FOREIGN KEY (A_Parent_Asset_ID) REFERENCES A_ASSET;

ALTER TABLE A_ASSET_CHANGE ADD CONSTRAINT ADepreciationTableHeader_AAss2 FOREIGN KEY (A_Depreciation_Table_Header_ID) REFERENCES A_DEPRECIATION_TABLE_HEADER;

ALTER TABLE A_ASSET_GROUP_ACCT ADD CONSTRAINT ADepreciationTableHeader_AAss3 FOREIGN KEY (A_Depreciation_Table_Header_ID) REFERENCES A_DEPRECIATION_TABLE_HEADER;

ALTER TABLE A_ASSET_CHANGE ADD CONSTRAINT AdUser_AAssetChange FOREIGN KEY (Ad_User_ID) REFERENCES AD_USER;

ALTER TABLE A_ASSET_CHANGE ADD CONSTRAINT CAcctSchema_AAssetChange FOREIGN KEY (C_AcctSchema_ID) REFERENCES C_ACCTSCHEMA;

ALTER TABLE A_ASSET_CHANGE ADD CONSTRAINT CBPartnerLocation_AAssetChange FOREIGN KEY (C_BPartner_Location_ID) REFERENCES C_BPARTNER_LOCATION;

ALTER TABLE A_ASSET_CHANGE ADD CONSTRAINT CLocation_AAssetChange FOREIGN KEY (C_Location_ID) REFERENCES C_LOCATION;

ALTER TABLE A_ASSET_DISPOSED ADD CONSTRAINT AAssetTrade_AAssetDisposed FOREIGN KEY (A_Asset_Trade_ID) REFERENCES A_ASSET;

ALTER TABLE A_ASSET_DISPOSED ADD CONSTRAINT CPeriod_AAssetDisposed FOREIGN KEY (C_Period_ID) REFERENCES C_PERIOD;

ALTER TABLE A_ASSET_REVAL_ENTRY ADD CONSTRAINT CAcctSchema_AAssetRevalEntry FOREIGN KEY (C_AcctSchema_ID) REFERENCES C_ACCTSCHEMA;

ALTER TABLE A_ASSET_REVAL_ENTRY ADD CONSTRAINT CCurrency_AAssetRevalEntry FOREIGN KEY (C_Currency_ID) REFERENCES C_CURRENCY;

ALTER TABLE A_ASSET_REVAL_ENTRY ADD CONSTRAINT CDocType_AAssetRevalEntry FOREIGN KEY (C_DocType_ID) REFERENCES C_DOCTYPE;

ALTER TABLE A_ASSET_REVAL_ENTRY ADD CONSTRAINT CPeriod_AAssetRevalEntry FOREIGN KEY (C_Period_ID) REFERENCES C_PERIOD;

ALTER TABLE A_ASSET_REVAL_ENTRY ADD CONSTRAINT GLCategory_AAssetRevalEntry FOREIGN KEY (GL_Category_ID) REFERENCES GL_CATEGORY;

ALTER TABLE A_ASSET_SPLIT ADD CONSTRAINT CPeriod_AAssetSplit FOREIGN KEY (C_Period_ID) REFERENCES C_PERIOD;

ALTER TABLE A_ASSET_TRANSFER ADD CONSTRAINT CAcctSchema_AAssetTransfer FOREIGN KEY (C_AcctSchema_ID) REFERENCES C_ACCTSCHEMA;

ALTER TABLE A_ASSET_TRANSFER ADD CONSTRAINT CPeriod_AAssetTransfer FOREIGN KEY (C_Period_ID) REFERENCES C_PERIOD;

ALTER TABLE A_DEPRECIATION_BUILD ADD CONSTRAINT AEndAsset_ADepreciationBuild FOREIGN KEY (A_End_Asset_ID) REFERENCES A_ASSET;

ALTER TABLE A_DEPRECIATION_BUILD ADD CONSTRAINT AStartAsset_ADepreciationBuild FOREIGN KEY (A_Start_Asset_ID) REFERENCES A_ASSET;

ALTER TABLE A_DEPRECIATION_BUILD ADD CONSTRAINT CPeriod_ADepreciationBuild FOREIGN KEY (C_Period_ID) REFERENCES C_PERIOD;

ALTER TABLE A_DEPRECIATION_ENTRY ADD CONSTRAINT CAcctSchema_ADepreciationEntry FOREIGN KEY (C_AcctSchema_ID) REFERENCES C_ACCTSCHEMA;

ALTER TABLE A_DEPRECIATION_ENTRY ADD CONSTRAINT CCurrency_ADepreciationEntry FOREIGN KEY (C_Currency_ID) REFERENCES C_CURRENCY;

ALTER TABLE A_DEPRECIATION_ENTRY ADD CONSTRAINT CDocType_ADepreciationEntry FOREIGN KEY (C_DocType_ID) REFERENCES C_DOCTYPE;

ALTER TABLE A_DEPRECIATION_ENTRY ADD CONSTRAINT CPeriod_ADepreciationEntry FOREIGN KEY (C_Period_ID) REFERENCES C_PERIOD;

ALTER TABLE A_DEPRECIATION_ENTRY ADD CONSTRAINT GLCategory_ADepreciationEntry FOREIGN KEY (GL_Category_ID) REFERENCES GL_CATEGORY;

ALTER TABLE A_DEPRECIATION_FORECAST ADD CONSTRAINT AEndAsset_ADepreciationForecas FOREIGN KEY (A_End_Asset_ID) REFERENCES A_ASSET;

ALTER TABLE A_DEPRECIATION_FORECAST ADD CONSTRAINT AStartAsset_ADepreciationForec FOREIGN KEY (A_Start_Asset_ID) REFERENCES A_ASSET;

ALTER TABLE C_INVOICELINE ADD CONSTRAINT AAssetGroup_CInvoiceLine FOREIGN KEY (A_Asset_Group_ID) REFERENCES A_ASSET_GROUP;

ALTER TABLE GL_JOURNALLINE ADD CONSTRAINT AAsset_GLJournalLine FOREIGN KEY (A_Asset_ID) REFERENCES A_ASSET;

ALTER TABLE GL_JOURNALLINE ADD CONSTRAINT AAssetGroup_GLJournalLine FOREIGN KEY (A_Asset_Group_ID) REFERENCES A_ASSET_GROUP;

ALTER TABLE I_ASSET ADD CONSTRAINT AAssetGroup_IAsset FOREIGN KEY (A_Asset_Group_ID) REFERENCES A_ASSET_GROUP;

ALTER TABLE I_ASSET ADD CONSTRAINT ADepreciationTableHeader_IAsse FOREIGN KEY (A_Depreciation_Table_Header_ID) REFERENCES A_DEPRECIATION_TABLE_HEADER;

ALTER TABLE I_ASSET ADD CONSTRAINT CAcctSchema_IAsset FOREIGN KEY (C_AcctSchema_ID) REFERENCES C_ACCTSCHEMA;

ALTER TABLE I_ASSET ADD CONSTRAINT CBPartner_IAsset FOREIGN KEY (C_BPartner_ID) REFERENCES C_BPARTNER;

ALTER TABLE I_ASSET ADD CONSTRAINT CBPartnerLocation_IAsset FOREIGN KEY (C_BPartner_Location_ID) REFERENCES C_BPARTNER_LOCATION;

ALTER TABLE I_ASSET ADD CONSTRAINT CLocation_IAsset FOREIGN KEY (C_Location_ID) REFERENCES C_LOCATION;

ALTER TABLE I_ASSET ADD CONSTRAINT MLocator_IAsset FOREIGN KEY (M_Locator_ID) REFERENCES M_LOCATOR;

ALTER TABLE I_ASSET ADD CONSTRAINT MProduct_IAsset FOREIGN KEY (M_Product_ID) REFERENCES M_PRODUCT;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT ADOrgDoc_IFAJournal FOREIGN KEY (AD_OrgDoc_ID) REFERENCES AD_ORG;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT ADOrgTrx_IFAJournal FOREIGN KEY (AD_OrgTrx_ID) REFERENCES AD_ORG;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT CAcctSchema_IFAJournal FOREIGN KEY (C_AcctSchema_ID) REFERENCES C_ACCTSCHEMA;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT CActivity_IFAJournal FOREIGN KEY (C_Activity_ID) REFERENCES C_ACTIVITY;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT CBPartner_IFAJournal FOREIGN KEY (C_BPartner_ID) REFERENCES C_BPARTNER;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT CCampaign_IFAJournal FOREIGN KEY (C_Campaign_ID) REFERENCES C_CAMPAIGN;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT CCurrency_IFAJournal FOREIGN KEY (C_Currency_ID) REFERENCES C_CURRENCY;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT CDocType_IFAJournal FOREIGN KEY (C_DocType_ID) REFERENCES C_DOCTYPE;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT Account_IFAJournal FOREIGN KEY (Account_ID) REFERENCES C_ELEMENTVALUE;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT User1_IFAJournal FOREIGN KEY (User1_ID) REFERENCES C_ELEMENTVALUE;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT User2_IFAJournal FOREIGN KEY (User2_ID) REFERENCES C_ELEMENTVALUE;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT CPeriod_IFAJournal FOREIGN KEY (C_Period_ID) REFERENCES C_PERIOD;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT CProject_IFAJournal FOREIGN KEY (C_Project_ID) REFERENCES C_PROJECT;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT CSalesRegion_IFAJournal FOREIGN KEY (C_SalesRegion_ID) REFERENCES C_SALESREGION;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT CUOM_IFAJournal FOREIGN KEY (C_UOM_ID) REFERENCES C_UOM;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT CValidCombination_IFAJournal FOREIGN KEY (C_ValidCombination_ID) REFERENCES C_VALIDCOMBINATION;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT GLBudget_IFAJournal FOREIGN KEY (GL_Budget_ID) REFERENCES GL_BUDGET;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT GLCategory_IFAJournal FOREIGN KEY (GL_Category_ID) REFERENCES GL_CATEGORY;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT GLJournal_IFAJournal FOREIGN KEY (GL_Journal_ID) REFERENCES GL_JOURNAL;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT GLJournalBatch_IFAJournal FOREIGN KEY (GL_JournalBatch_ID) REFERENCES GL_JOURNALBATCH;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT GLJournalLine_IFAJournal FOREIGN KEY (GL_JournalLine_ID) REFERENCES GL_JOURNALLINE;

ALTER TABLE I_FAJOURNAL ADD CONSTRAINT MProduct_IFAJournal FOREIGN KEY (M_Product_ID) REFERENCES M_PRODUCT;

-- Errors ORA-02267 - possibly dictionary column definition or database column wrong definition errors

-- ALTER TABLE A_ASSET_CHANGE ADD CONSTRAINT AAssetSpreadT_AAssetChange FOREIGN KEY (A_Asset_Spread_Type) REFERENCES A_ASSET_SPREAD;

-- ALTER TABLE A_ASSET_CHANGE ADD CONSTRAINT DepreciationT_AAssetChange FOREIGN KEY (DepreciationType) REFERENCES A_DEPRECIATION;

-- ALTER TABLE A_ASSET_CHANGE ADD CONSTRAINT ConventionT_AAssetChange FOREIGN KEY (ConventionType) REFERENCES A_DEPRECIATION_CONVENTION;

-- ALTER TABLE A_ASSET_CHANGE ADD CONSTRAINT ADepreciationCalcT_AAssetChang FOREIGN KEY (A_Depreciation_Calc_Type) REFERENCES A_DEPRECIATION_METHOD;

-- ALTER TABLE A_ASSET_GROUP_ACCT ADD CONSTRAINT AAssetSpreadT_AAssetGroupAcct FOREIGN KEY (A_Asset_Spread_Type) REFERENCES A_ASSET_SPREAD;

-- ALTER TABLE A_ASSET_GROUP_ACCT ADD CONSTRAINT DepreciationT_AAssetGroupAcct FOREIGN KEY (DepreciationType) REFERENCES A_DEPRECIATION;

-- ALTER TABLE A_ASSET_GROUP_ACCT ADD CONSTRAINT ConventionT_AAssetGroupAcct FOREIGN KEY (ConventionType) REFERENCES A_DEPRECIATION_CONVENTION;

-- ALTER TABLE A_ASSET_GROUP_ACCT ADD CONSTRAINT ADepreciationCalcT_AAssetGroup FOREIGN KEY (A_Depreciation_Calc_Type) REFERENCES A_DEPRECIATION_METHOD;

-- ALTER TABLE A_ASSET_SPLIT ADD CONSTRAINT AAssetID_AAssetSplit FOREIGN KEY (A_Asset_ID_To) REFERENCES A_ASSET;

-- ALTER TABLE I_ASSET ADD CONSTRAINT AAssetSpreadT_IAsset FOREIGN KEY (A_Asset_Spread_Type) REFERENCES A_ASSET_SPREAD;

-- ALTER TABLE I_ASSET ADD CONSTRAINT DepreciationT_IAsset FOREIGN KEY (DepreciationType) REFERENCES A_DEPRECIATION;

-- ALTER TABLE I_ASSET ADD CONSTRAINT ConventionT_IAsset FOREIGN KEY (ConventionType) REFERENCES A_DEPRECIATION_CONVENTION;

-- ALTER TABLE I_ASSET ADD CONSTRAINT ADepreciationCalcT_IAsset FOREIGN KEY (A_Depreciation_Calc_Type) REFERENCES A_DEPRECIATION_METHOD;